<?php 

require_once("form/index.php");

class Test {
	
	var $error;
	var $ok;
	
	public function __construct(){
		$name = get_class($this);
		$this->header($name);
		$this->error = new Html("p", array("class" => "error"));
		$this->ok = new Html("p", array("class" => "ok"));
	}
	
	public function assert($expected, $value){
		return ($expected === $value);
	}
	
	public function assertEquals($expected, $value, $text = "%s equals %s"){
		if(!$this->assert($expected, $value)){
			$this->log(sprintf($text, htmlentities($expected), htmlentities($value)), "error");
		} else {
			$this->log(sprintf($text, htmlentities($expected), htmlentities($value)), "ok");
		}
	}
	
	public function assertNotEquals($expected, $value, $text = "%s not equals %s"){
		if($this->assert($expected, $value)){
			$this->log(sprintf($text, $expected, $value), "error");
		} else {
			$this->log(sprintf($text, $expected, $value), "ok");
		}
	}
	
	public function assertTrue($value, $text = "%s is TRUE"){
		if($value){
			$this->log(sprintf($text, $expected, $value), "ok");
		} else {
			$this->log(sprintf($text, $expected, $value), "error");
		}
	}
	
	public function assertFalse($value, $text = "%s is FALSE"){
		if(!$value){
			$this->log(sprintf($text, $value), "ok");
		} else {
			$this->log(sprintf($text, $value), "error");
		}
	}
	
	public function assertEmpty($value, $text = "Value is empty"){
		if(empty($value)){
			$this->log(sprintf($text, $value), "ok");
		} else {
			$this->log(sprintf($text, $value), "error");
		}
	}
	
	public function assertNotEmpty($value, $text = "%s is not empty"){
		if(!empty($value)){
			$this->log(sprintf($text, $value), "ok");
		} else {
			$this->log(sprintf($text, $value), "error");
		}
	}
	
	private function header($name){
		$name = str_replace("Test", " Tests", $name);
		include("tests/header.php");
	}
	
	private function log($text, $klass){
		echo $this->$klass->open() . $text . $this->$klass->close();
	}
	
}